import apiCommon from './api-common';
export default {

  /**
   * 根据表名获取所有字段
   * @param {string} tableName 表名
   * @param {string} packageCode 数据包code
   */
  getMappingOptions(tableName, packageCode) {
    return window._UIDesingerAxios({
      method: 'get',
      url: `/xtag/xtagservice/v1/xtag/column/columnList?packageCode=${packageCode}&tableAlias=${tableName}`,
    });
  },

  /**
   * 获取用于渲染图表的数据
   * @param {object} params 接口入参
   * @param {string} tableName 表名
   * @param {string} packageCode 数据包code
   */
  getChartData(params, tableName, packageCode) {
    const _params = apiCommon.clearParams(params);
    return window._UIDesingerAxios({
      method: 'post',
      url: `/quality/api/v1/xtagDataConvert/getValueByTableNameAndFields/${tableName}?packageCode=${packageCode}`,
      data: _params,
      headers: {
        'Content-Type': 'application/json',
      },
    });
  },

  /**
   * 获取xtag 对应数据表 数据
   * @param {string} tableName 数据表名称
   * @param {object} params 接口入参
   * @param {string} packageCode 数据包code
   */
  getTableData(tableName, params, packageCode) {
    return window._UIDesingerAxios({
      method: 'post',
      url: `/quality/api/v1/xtagDataConvert/viewColumnsByTableName/${tableName}?packageCode=${packageCode}`,
      data: params,
      headers: {
        'Content-Type': 'application/json',
      },
    });
  },

  // 根据租户查询所有数据包
  getDataPackageByTenantCode() {
    return window._UIDesingerAxios({
      method: 'get',
      url: '/xtag/xtagservice/v1/xtag/datapackage/packages',
    });
  },

  /**
   * 根据租户查询租户可访问的所有数据表
   */
  getDataTableListByTenantCodeAndPackageCode(packageCode) {
    return window._UIDesingerAxios({
      method: 'get',
      url: `/xtag/xtagservice/v1/xtag/packagetables/tables?packageCode=${packageCode}`,
    });
  },

  /**
   * 根据数据包code和数据表name获取对应数据表的sql参数
   */
  getTableSqlParams(packageCode, tableAlias) {
    return window._UIDesingerAxios({
      method: 'get',
      url: `/xtag/xtagservice/v1/xtag/packagetables/sqlParam?packageCode=${packageCode}&tableAlias=${tableAlias}`,
    });
  },

  exportAllValueByTableNameAndFields(tableName, params, packageCode) {
    return window._UIDesingerAxios({
      method: 'post',
      url: `/quality/api/v1/xtagDataConvert/exportAllValueByTableNameAndFields/${tableName}?packageCode=${packageCode}`,
      data: params,
      headers: {
        'Content-Type': 'application/json',
      },
    });
  },
};
